package com.skywolf.chem.manager;


import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.common.sysconfig.response.RespData;
import com.skywolf.chem.customer.entity.Customer;
import com.skywolf.chem.customer.service.ICustomerService;
import com.skywolf.chem.home.entity.LoopImg;
import com.skywolf.chem.home.entity.LoopImgVo;
import com.skywolf.chem.home.entity.UsersVo;
import com.skywolf.chem.home.service.ILoopImgService;
import com.skywolf.chem.manager.param.CusManagerParam;
import com.skywolf.chem.manager.param.LoopImgManagerParam;
import com.skywolf.chem.utils.CryptUtil;
import com.skywolf.chem.utils.RequestConstans;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 轮播图配置表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/manager/customer")
public class CustomerManagerController {

    @Autowired
    private ICustomerService customerService;

    @ApiOperation(value = "获取注册用户")
    @RequestMapping(value = "/getUsers",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<PageVO<UsersVo>> getUsers(@RequestBody @Validated CusManagerParam queryParam) {
        PageVO<UsersVo> obj= customerService.pageUsersList(queryParam);
        return RespData.success(obj);
    }

    @ApiOperation(value = "重置密码")
    @RequestMapping(value = "/updatePwd",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<String> updatePwd(@RequestBody @Validated CusManagerParam queryParam) {
        if(queryParam==null || StringUtils.isBlank(queryParam.getPwd())
                || queryParam.getPwd().length()<6){
            return RespData.failResult("密码为6-12位的字符");
        }
        Customer user = new Customer();
        user.setPassword(CryptUtil.encryptAES128(queryParam.getPwd(), RequestConstans.decode_pwd));
        user.setId(queryParam.getId());
        customerService.updateById(user);
        return RespData.success("success");
    }

}
